/**
 * fileName:  ParamValueRelWriter.java
 * author:  Lei
 * Company:  Cloudland Studio
 * Createdate:  2014-6-11 下午10:42:16
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-11          Lei            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.store.write;

import javax.annotation.Resource;

import org.cloudland.commercial.masterdata.store.DatabaseWrite;
import org.cloudland.commercial.masterdata.store.entity.ParamValueRelEntity;
import org.cloudland.jdbc.ibatis.masterdata.entity.CategoryArgumentRelationEntity;
import org.cloudland.jdbc.ibatis.masterdata.handler.CategoryArgumentRelationMapper;
import org.cloudland.util.Randoms;
import org.springframework.stereotype.Service;

 /**
 * <pre> 
 * TODO 请充分描述该类提供的作用, 或与其他类会有关联的使用。
 * 使用 java.lang.Object#toString(), 或者 {@link java.lang.Character Character} 等标签
 * </pre>
 * @ClassName  ParamValueRelWriter
 * @author  Lei
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
@Service
public class ParamValueRelWriter implements DatabaseWrite<ParamValueRelEntity> {

	@Resource(name = "categoryArgumentRelationMapper")
	private CategoryArgumentRelationMapper relationMapper;
	
	/**
	 * <pre>
	 * TODO 请充分描述该构造函数的作用，及其参数的作用。
	 * </pre>
	 *   
	 */
	public ParamValueRelWriter() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param entity
	 */
	public void save(ParamValueRelEntity entity) {
		
		String uuid = Randoms.uuid();
		entity.setId(uuid);
		short sort = Short.parseShort(String.valueOf(entity.getSort()));
		
		CategoryArgumentRelationEntity  entityDao = new CategoryArgumentRelationEntity(entity.getId(), entity.getCategoryId(), entity.getArgumentId(), entity.getCostId(), entity.getChooseType().value(), sort);
		relationMapper.add(entityDao);
	}
	
	/**
	 * @param entity
	 */
	public void update(ParamValueRelEntity entity) {
		short sort = Short.parseShort(entity.getSort().toString());
		
		CategoryArgumentRelationEntity  entityDao = new CategoryArgumentRelationEntity(entity.getId(), entity.getCategoryId(), entity.getArgumentId(), entity.getCostId(), entity.getChooseType().value(), sort);
		relationMapper.update(entityDao);
	}
	
	/**
	 * @param entity
	 */
	public void delete(ParamValueRelEntity entity) {
		CategoryArgumentRelationEntity  entityDao = new CategoryArgumentRelationEntity(entity.getId(), "", "", "", (short) 1, (short) 1);
		relationMapper.delete(entityDao);
		
	}
	
}
